/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package su.samlib.informer.database.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author rikland
 */
@Entity
@Table(name = "library")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Library.findAll", query = "SELECT l FROM Library l"),
    @NamedQuery(name = "Library.findByLibraryId", query = "SELECT l FROM Library l WHERE l.libraryId = :libraryId"),
    @NamedQuery(name = "Library.findByLibraryTitle", query = "SELECT l FROM Library l WHERE l.libraryTitle = :libraryTitle"),
    @NamedQuery(name = "Library.findByLibraryUrl", query = "SELECT l FROM Library l WHERE l.libraryUrl = :libraryUrl")})
public class Library implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "library_id")
//    @GeneratedValue(generator="library_library_id_seq")
//    @SequenceGenerator(name="library_library_id_seq",sequenceName="library_library_id_seq",allocationSize=1)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer libraryId;
    @Basic(optional = false)
    @Column(name = "library_title", nullable = false, length = 250)
    private String libraryTitle;
    @Basic(optional = false)
    @Column(name = "library_url", nullable = false, length = 50)
    private String libraryUrl;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "libraryId")
    private List<Author> authorList;

    public Library() {
    }

    public Library(Integer libraryId) {
        this.libraryId = libraryId;
    }

    public Library(Integer libraryId, String libraryTitle, String libraryUrl) {
        this.libraryId = libraryId;
        this.libraryTitle = libraryTitle;
        this.libraryUrl = libraryUrl;
    }

    public Integer getLibraryId() {
        return libraryId;
    }

    public void setLibraryId(Integer libraryId) {
        this.libraryId = libraryId;
    }

    public String getLibraryTitle() {
        return libraryTitle;
    }

    public void setLibraryTitle(String libraryTitle) {
        this.libraryTitle = libraryTitle;
    }

    public String getLibraryUrl() {
        return libraryUrl;
    }

    public void setLibraryUrl(String libraryUrl) {
        this.libraryUrl = libraryUrl;
    }

    @XmlTransient
    public List<Author> getAuthorList() {
        return authorList;
    }

    public void setAuthorList(List<Author> authorList) {
        this.authorList = authorList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (libraryId != null ? libraryId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Library)) {
            return false;
        }
        Library other = (Library) object;
        if ((this.libraryId == null && other.libraryId != null) || (this.libraryId != null && !this.libraryId.equals(other.libraryId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "su.samlib.informer.database.model.Library[ libraryId=" + libraryId + " ]";
    }
    
}
